<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="熊市" prop="bearMarket">
        <el-input
          v-model="queryParams.bearMarket"
          placeholder="请输入熊市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="牛市" prop="bullMarket">
        <el-input
          v-model="queryParams.bullMarket"
          placeholder="请输入牛市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颈项开始" prop="cattleStart">
        <el-input
          v-model="queryParams.cattleStart"
          placeholder="请输入颈项开始"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="死叉" prop="deathCross">
        <el-input
          v-model="queryParams.deathCross"
          placeholder="请输入死叉"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下降趋势" prop="downTrend">
        <el-input
          v-model="queryParams.downTrend"
          placeholder="请输入下降趋势"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金叉" prop="goldenCross">
        <el-input
          v-model="queryParams.goldenCross"
          placeholder="请输入金叉"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="kdj死叉" prop="kdjDeathCross">
        <el-input
          v-model="queryParams.kdjDeathCross"
          placeholder="请输入kdj死叉"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="kdj金叉" prop="kdjGoldenCross">
        <el-input
          v-model="queryParams.kdjGoldenCross"
          placeholder="请输入kdj金叉"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="超买" prop="overBought">
        <el-input
          v-model="queryParams.overBought"
          placeholder="请输入超买"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="超卖" prop="overSold">
        <el-input
          v-model="queryParams.overSold"
          placeholder="请输入超卖"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意愿等级" prop="prosperityLevel">
        <el-input
          v-model="queryParams.prosperityLevel"
          placeholder="请输入意愿等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短期下降趋势" prop="shortDownwardTrend">
        <el-input
          v-model="queryParams.shortDownwardTrend"
          placeholder="请输入短期下降趋势"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="短期上涨趋势" prop="shortUpwardTrend">
        <el-input
          v-model="queryParams.shortUpwardTrend"
          placeholder="请输入短期上涨趋势"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="股票号码" prop="stockNum">
        <el-input
          v-model="queryParams.stockNum"
          placeholder="请输入股票号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术回归" prop="technicalReturn">
        <el-input
          v-model="queryParams.technicalReturn"
          placeholder="请输入技术回归"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上升趋势" prop="upTrend">
        <el-input
          v-model="queryParams.upTrend"
          placeholder="请输入上升趋势"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateDate">
        <el-input
          v-model="queryParams.updateDate"
          placeholder="请输入更新时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['stock:echnicalaspect:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['stock:echnicalaspect:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['stock:echnicalaspect:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['stock:echnicalaspect:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="echnicalaspectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="echnicalaspectId" />
      <el-table-column label="熊市" align="center" prop="bearMarket" />
      <el-table-column label="牛市" align="center" prop="bullMarket" />
      <el-table-column label="颈项开始" align="center" prop="cattleStart" />
      <el-table-column label="死叉" align="center" prop="deathCross" />
      <el-table-column label="下降趋势" align="center" prop="downTrend" />
      <el-table-column label="金叉" align="center" prop="goldenCross" />
      <el-table-column label="kdj死叉" align="center" prop="kdjDeathCross" />
      <el-table-column label="kdj金叉" align="center" prop="kdjGoldenCross" />
      <el-table-column label="超买" align="center" prop="overBought" />
      <el-table-column label="超卖" align="center" prop="overSold" />
      <el-table-column label="意愿等级" align="center" prop="prosperityLevel" />
      <el-table-column label="短期下降趋势" align="center" prop="shortDownwardTrend" />
      <el-table-column label="短期上涨趋势" align="center" prop="shortUpwardTrend" />
      <el-table-column label="股票号码" align="center" prop="stockNum" />
      <el-table-column label="技术回归" align="center" prop="technicalReturn" />
      <el-table-column label="上升趋势" align="center" prop="upTrend" />
      <el-table-column label="更新时间" align="center" prop="updateDate" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['stock:echnicalaspect:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['stock:echnicalaspect:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改技术分析对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="熊市" prop="bearMarket">
          <el-input v-model="form.bearMarket" placeholder="请输入熊市" />
        </el-form-item>
        <el-form-item label="牛市" prop="bullMarket">
          <el-input v-model="form.bullMarket" placeholder="请输入牛市" />
        </el-form-item>
        <el-form-item label="颈项开始" prop="cattleStart">
          <el-input v-model="form.cattleStart" placeholder="请输入颈项开始" />
        </el-form-item>
        <el-form-item label="死叉" prop="deathCross">
          <el-input v-model="form.deathCross" placeholder="请输入死叉" />
        </el-form-item>
        <el-form-item label="下降趋势" prop="downTrend">
          <el-input v-model="form.downTrend" placeholder="请输入下降趋势" />
        </el-form-item>
        <el-form-item label="金叉" prop="goldenCross">
          <el-input v-model="form.goldenCross" placeholder="请输入金叉" />
        </el-form-item>
        <el-form-item label="kdj死叉" prop="kdjDeathCross">
          <el-input v-model="form.kdjDeathCross" placeholder="请输入kdj死叉" />
        </el-form-item>
        <el-form-item label="kdj金叉" prop="kdjGoldenCross">
          <el-input v-model="form.kdjGoldenCross" placeholder="请输入kdj金叉" />
        </el-form-item>
        <el-form-item label="超买" prop="overBought">
          <el-input v-model="form.overBought" placeholder="请输入超买" />
        </el-form-item>
        <el-form-item label="超卖" prop="overSold">
          <el-input v-model="form.overSold" placeholder="请输入超卖" />
        </el-form-item>
        <el-form-item label="意愿等级" prop="prosperityLevel">
          <el-input v-model="form.prosperityLevel" placeholder="请输入意愿等级" />
        </el-form-item>
        <el-form-item label="短期下降趋势" prop="shortDownwardTrend">
          <el-input v-model="form.shortDownwardTrend" placeholder="请输入短期下降趋势" />
        </el-form-item>
        <el-form-item label="短期上涨趋势" prop="shortUpwardTrend">
          <el-input v-model="form.shortUpwardTrend" placeholder="请输入短期上涨趋势" />
        </el-form-item>
        <el-form-item label="股票号码" prop="stockNum">
          <el-input v-model="form.stockNum" placeholder="请输入股票号码" />
        </el-form-item>
        <el-form-item label="技术回归" prop="technicalReturn">
          <el-input v-model="form.technicalReturn" placeholder="请输入技术回归" />
        </el-form-item>
        <el-form-item label="上升趋势" prop="upTrend">
          <el-input v-model="form.upTrend" placeholder="请输入上升趋势" />
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-input v-model="form.updateDate" placeholder="请输入更新时间" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEchnicalaspect, getEchnicalaspect, delEchnicalaspect, addEchnicalaspect, updateEchnicalaspect } from "@/api/stock/echnicalaspect";

export default {
  name: "Echnicalaspect",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 技术分析表格数据
      echnicalaspectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bearMarket: null,
        bullMarket: null,
        cattleStart: null,
        deathCross: null,
        downTrend: null,
        goldenCross: null,
        kdjDeathCross: null,
        kdjGoldenCross: null,
        overBought: null,
        overSold: null,
        prosperityLevel: null,
        shortDownwardTrend: null,
        shortUpwardTrend: null,
        stockNum: null,
        technicalReturn: null,
        upTrend: null,
        updateDate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询技术分析列表 */
    getList() {
      this.loading = true;
      listEchnicalaspect(this.queryParams).then(response => {
        this.echnicalaspectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        echnicalaspectId: null,
        bearMarket: null,
        bullMarket: null,
        cattleStart: null,
        deathCross: null,
        downTrend: null,
        goldenCross: null,
        kdjDeathCross: null,
        kdjGoldenCross: null,
        overBought: null,
        overSold: null,
        prosperityLevel: null,
        shortDownwardTrend: null,
        shortUpwardTrend: null,
        stockNum: null,
        technicalReturn: null,
        upTrend: null,
        updateDate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.echnicalaspectId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加技术分析";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const echnicalaspectId = row.echnicalaspectId || this.ids
      getEchnicalaspect(echnicalaspectId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改技术分析";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.echnicalaspectId != null) {
            updateEchnicalaspect(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEchnicalaspect(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const echnicalaspectIds = row.echnicalaspectId || this.ids;
      this.$modal.confirm('是否确认删除技术分析编号为"' + echnicalaspectIds + '"的数据项？').then(function() {
        return delEchnicalaspect(echnicalaspectIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('stock/echnicalaspect/export', {
        ...this.queryParams
      }, `echnicalaspect_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
